package org.tinygroup.cepcoremonitor;

import org.tinygroup.cepcore.CEPCore;
import org.tinygroup.cepcore.EventProcessor;
import org.tinygroup.event.Event;

public class MonitorUtil {
	/**
	 * 此方法在计算出event所执行的processor后即可调用
	 * 添加from/to信息，from当前节点的nodeName,to目标处理器的id
	 * 如果是远程请求，目标处理器id为目标节点的ip:port:nodeName
	 * 如果是本地请求，目标处理器就是本地处理器id
	 * @param e 请求事件对象
	 * @param core 当前节点cepcore
	 * @param processor 目标处理器
	 */
	public static void addMonitorInfo(Event e, CEPCore core,EventProcessor processor){
		addFormInfo(e, core);
		addToInfo(e, processor);
	}
	public static void addFormInfo(Event e, CEPCore core) {
		e.getServiceRequest().getContext().put(MonitorConstants.FORM_NODE, core.getNodeName());
	}

	public static void addToInfo(Event e, EventProcessor processor) {
		e.getServiceRequest().getContext().put(MonitorConstants.TO_NODE, processor.getId());
	}
}
